package server

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"go-gin-test-001/entity/result"
	"go-gin-test-001/router"
	"net/http"
)

func SetupServer() *gin.Engine {
	r := gin.Default()
	// 404,405处理
	r.NoMethod(func(context *gin.Context) {
		fmt.Println("no method")
		context.JSON(http.StatusMethodNotAllowed, result.NotSupportMethodR())
	})
	r.NoRoute(func(context *gin.Context) {
		fmt.Println("no route")
		context.JSON(http.StatusNotFound, result.NotFoundR())
	})

	// 注册路由
	r.GET("/hello", router.Hello)

	return r
}
